package com.lfnyxy.service.org.imp;

import com.lfnyxy.dao.org.MenuDetailDao;
import com.lfnyxy.entity.org.MenuDetailEntity;
import com.lfnyxy.query.org.MenuDetailQuery;
import com.lfnyxy.service.org.MenuDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuDetailServiceImp implements MenuDetailService {
    @Autowired
    public MenuDetailDao menuDetailDao;

    public int CreateItem(MenuDetailEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return menuDetailDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(MenuDetailEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return menuDetailDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List<MenuDetailEntity> QueryPageList(MenuDetailQuery query) {
        int count = menuDetailDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return menuDetailDao.QueryPageList(query);
        }
        return null;
    }

    public List<MenuDetailEntity> QueryAll() {
        return menuDetailDao.QueryAll();
    }

    public MenuDetailEntity QueryItem(int Id) {
        if (Id > 0) {
            return menuDetailDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return menuDetailDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(MenuDetailEntity entity) {
        if (entity != null) {
            return menuDetailDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}